/**
 * 
 */
package com.java.framework.utils.taglib;

import com.java.framework.utils.page.Pager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.TagSupport;
import java.io.IOException;

/****
 * 分页标签
 * 
 * @author sunshine
 */
public class PageTag extends TagSupport {

  private static final long serialVersionUID = 9066446776126250721L;

  private static final Logger log = LoggerFactory.getLogger(PageTag.class);

  private Pager<?> page = null;

  private String implBean = null;

//  private String characterCoding = null;

  private String funcName = null; // 设置点击页码调用的js函数名称，默认为page，在一页有多个分页对象时使用。

  public PageTag() {
    super();
    init();
  }

  @Override
  public void release() {
    super.release();
    init();
  }

  private void init() {
    funcName = "page";
    page = null;
//    characterCoding = null;
  }

  public int doStartTag() throws JspException {
    try {
      pageContext.getOut().print(page.toString());
    } catch (IOException e) {
      log.error(e.getMessage());
    }
    return SKIP_BODY;
  }

  public int doEndTag() throws JspException {
    init();
    return EVAL_PAGE;
  }

  public Pager<?> getPage() {
    return page;
  }

  public void setPage(Pager<?> page) {
    this.page = page;
  }

  public String getFuncName() {
    return funcName;
  }

  public void setFuncName(String funcName) {
    this.funcName = funcName;
  }

  public String getImplBean() {
    return implBean;
  }

  public void setImplBean(String implBean) {
    this.implBean = implBean;
  }

}
